﻿using EFCore.DBBase.SqlSugar;
using EFCore.Injector;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Yookey.GSFJCSZF.IRepository;
using Yookey.GSFJCSZF.Models;

namespace Yookey.GSFJCSZF.Repository
{
    public class DemoRepository: IDemoRepository, ITransientDependency
    {
        public async Task<Demos> SelectSingle()
        {
            using (var db = SugerHandler.Instance())
            {
                return await db.QueryAsync<Demos>(o => o.Id == "ABC");
            }
        }

        public async Task<List<Demos>> SelectList(string keywords)
        {
            using (var db = SugerHandler.Instance())
            {
                QueryDescriptor queryCondition = new QueryDescriptor
                {
                    PageSize = 2,
                    PageIndex = 1,
                    OrderBys = new List<OrderByClause> {
                        new OrderByClause { Sort ="Title",Order = OrderSequence.Desc }
                    },
                    Conditions = new List<QueryCondition> {
                        new QueryCondition{ Key="Title",Operator =QueryOperator.Like,Value=keywords}
                    }
                };
                return await db.QueryListAsync<Demos>(queryCondition);
            }
        }
    }
}
